package hello.base;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.time.LocalDateTime;



@ToString
@JsonInclude(JsonInclude.Include.NON_NULL)
public class HttpResponse<T> implements Serializable {
    private static final int SUCCESS = 200;
    private static final int FAIL = 500;
    private static final long serialVersionUID = 1L;
    @Getter
    @Setter
    private String msg = "success";

    @Getter
    @Setter
    private int code = SUCCESS;


    @Getter
    @Setter
    private LocalDateTime timestamp = LocalDateTime.now();

    @Getter
    @Setter
    private T data;

    public HttpResponse() {
        super();
    }

    public HttpResponse(T data) {
        super();
        this.data = data;
    }

    public HttpResponse(T data, String msg) {
        super();
        this.data = data;
        this.msg = msg;
    }

    public HttpResponse(Throwable e) {
        super();
        this.msg = e.getMessage();
        this.code = FAIL;
    }
}
